<?php

namespace app\admin\model\choi;

use think\Model;


class LanguageQuestion extends Model
{

    

    

    // 表名
    protected $table = 'language_question';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public function question()
    {
        return $this->hasOne(Question::class, 'question_id', 'question_id');
    }

    public static function getByLanguageId($languageId)
    {
        return self::with('question')->where('language_id', $languageId)->order('weigh desc')->select();
    }

    public function getQuestion($languageId, $questionId)
    {
        return $this->where('language_id', $languageId)->where('question_id', $questionId)->find();
    }

    /**
     * 删除
     */
    public static function del($languageId, $questionId)
    {
        return self::where('language_id', $languageId)->where('question_id', $questionId)->delete();
    }

    public static function getQuestionId($languageId)
    {
        return self::where('language_id', $languageId)->column('question_id');
    }


}
